clam
Files:Tags: No tags.from os import urandom
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
from PIL import Image
import numpy as np
p = next_prime(2^128)
F = GF(p)
R.<x> = PolynomialRing(F)
key = urandom(16)
secret = int.from_bytes(key, 'big')
k = 64
n = 128
poly = R.random_element(k-2) * x + F(secret)
px = []
for i in range(1, n+1):
bits = list(map(np.uint8, bin(int(poly(i)))[2:].zfill(128)))
row = [0] * 512
for j in range(4): row[j::4] = bits
for j in range(4): px.append(row)
im1 = Image.fromarray(np.asarray(px)*255, 'L').convert('RGBA')
with Image.open("mask.png") as im2:
Image.alpha_composite(im1, im2).save("out.png")
with open("flag.png", "rb") as f, open("flag.png.enc", "wb") as g:
cipher = AES.new(key, AES.MODE_CBC)
g.write(cipher.iv + cipher.encrypt(pad(f.read(), 16)))from PIL import Image
import numpy as np
matrix = [[(255, 0, 0) for j in range(128)] for i in range(128)]
with Image.open("out.png").convert('RGB') as im:
for i in range(128):
for j in range(128):
pixels = [im.getpixel((i * 4 + x, j * 4 + y)) for x in range(4) for y in range(4)]
if all(pixel == (255, 255, 255) for pixel in pixels):
matrix[j][i] = (255, 255, 255)
if all(pixel == (0, 0, 0) for pixel in pixels):
matrix[j][i] = (0, 0, 0)
out_im = Image.fromarray(np.asarray(matrix, np.uint8), 'RGB')
out_im.save("extract.png")
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 5, 7, 7, 8, 8, 8, 8, 8, 9, 9, 10, 11, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 15, 15, 15, 15, 15, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 21, 22, 22, 22, 22, 23, 23, 24, 24, 25, 25, 25, 25, 26, 26, 26, 27, 27, 27, 28, 30, 32, 36, 37, 40, 41, 42, 46, 48, 49, 51, 52, 52, 52, 52, 52, 52, 53, 54, 54, 54, 54, 54, 54, 55, 56, 56, 57, 57, 57, 57, 58, 58, 58, 59, 59, 60, 60] (edited)[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 5, 7, 7, 8, 8, 8, 8, 8, 9, 9, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 15, 15, 15, 16, 16, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 21, 22, 22, 22, 22, 23, 23, 24, 24, 25, 25, 25, 26, 26, 26, 27, 27, 27, 28, 50, 51, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 54, 55, 56, 57, 57, 57, 58, 58, 58, 59, 59, 60, 60, 60, 61, 61, 61, 61, 61, 61, 61, 61, 62]
it doesn't change too much, I'll give it a trydef solve_chall(obj):
return obj.LLL()UMDCTF{y0u_pull3d_@_g3m_0ut_0f_th3_m3ss}}